<template>
  <div id="performance-dashboard">
    <h1><span class="tb-icon"></span>个人绩效考核首页</h1>
    <div class="performance-summary">
      <div class="top-item-com top-itembc1">
        <h3>我的推广数</h3>
        <p>{{ myTradings }}</p>
      </div>
      <div class="top-item-com1 top-itembc2">
        <h3>我的绩效</h3>
        <p>{{ myPerformance }}</p>
      </div>
      <div class="top-item-com top-itembc3">
        <h3>我的提成</h3>
        <p>{{ myRoyalty }}</p>
      </div>
      <div class="top-item-com top-itembc4">
        <h3>总业绩</h3>
        <p>{{ allPerformance }}</p>
      </div>
    </div>
    <div class="detailed-performance">
      <h2><span class="tb-icon"></span>个人详细绩效记录</h2>
      <el-table v-loading="loading" :data="tradingOrderList">
        <el-table-column label="订单号" align="center" prop="orderNo" />
        <el-table-column label="网店编号" align="center" prop="tradingNum" />
        <el-table-column label="网店出售价格" align="center" prop="sellingPrice" />
        <el-table-column label="卖家到手价格" align="center" prop="handPrice" />
        <el-table-column label="业绩" align="center" prop="performance" />
        <el-table-column label="提成" align="center" prop="royalty" />
        <el-table-column label="订单状态" align="center" prop="orderStatus" :formatter="formatOrderStatus"/>
        <el-table-column label="订单类型" align="center" prop="orderType" :formatter="formatOrderType"/>
        <el-table-column label="订单所属人" align="center" prop="orderHolder" />
        <el-table-column label="网店所属人" align="center" prop="shopHolder" />
        <el-table-column label="订单完成时间" align="center" prop="completeTime" />
      </el-table>
    </div>
  </div>
</template>

<script>
import {myListTradingOrder} from "@/views/shop/api/tradingOrder";
import {myPerformance} from "@/views/shop/api/tradingPerformance";
import {myTradings} from "@/views/shop/api/trading";

export default {
  data() {
    return {
      // 遮罩层
      loading: true,
      myTradings: 0,
      myPerformance: 0,
      myRoyalty: 0,
      allPerformance: 0,
      tradingOrderList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        createUserId: null,
        createUserName: null,
        updateUserId: null,
        updateUserName: null,
        completeTime: null,
        discountAmount: null,
        handPrice: null,
        orderHolder: null,
        orderNo: null,
        orderRemark: null,
        orderStatus: null,
        orderType: null,
        performance: null,
        royalty: null,
        sellingPrice: null,
        shopHolder: null,
        tradingNum: null
      },
    };
  },
  created() {
    // 在这里可以调用API获取实际的数据
    this.getMyTradings();
    this.getMyPerformance();
    this.getList();
  },
  methods: {
    getMyTradings() {
      myTradings(this.queryParams).then(response => {
        console.log(response)
        this.myTradings = response.data;
        this.loading = false;
      });
    },
    getMyPerformance() {
      myPerformance(this.queryParams).then(response => {
        console.log(response)
        this.myPerformance = response.data.performance;
        this.allPerformance = response.data.allPerformance;
        this.myRoyalty = response.data.royalty;
        this.loading = false;
      });
      this.targetCompletionRate = 85;

    },

    getList() {
      this.loading = true;
      myListTradingOrder(this.queryParams).then(response => {
        this.tradingOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    formatOrderStatus(row, column, cellValue) {
      if (cellValue === '0') {
        return '生成';
      } else if (cellValue === '1') {
        return '完成';
      } else {
        return '未知状态';
      }
    },
    formatOrderType(row, column, cellValue) {
      if (cellValue === '0') {
        return '拍下';
      } else if (cellValue === '1') {
        return '手动添加';
      } else {
        return '未知状态';
      }
    },
  }
};
</script>

<style scoped>
#performance-dashboard {
  padding: 40px;
  font-family: Arial, sans-serif;
}

.performance-summary {
  display: flex;
  justify-content: space-around;
  margin-bottom: 20px;
}

.summary-item {
  border: 1px solid #ccc;
  padding: 10px;
  width: 20%;
  text-align: center;
}

.detailed-performance table {
  width: 100%;
  border-collapse: collapse;
}

.detailed-performance th, .detailed-performance td {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}
.top-item-com {
  border: 1px solid #2f89f3;
  border-radius: 8px;
  width: 200px;
  height: 100px;
  padding: 8px 16px;
  background-size: 100px 200px, 100% 100%;
  min-height: 140px;
  max-height: 254px;
}
.top-item-com1 {
  border: 1px solid #f7933c;
  width: 200px;
  border-radius: 8px;
  height: 100px;
  padding: 8px 16px;
  background-size: 100px 200px, 100% 100%;
  min-height: 140px;
  max-height: 254px;
}

.top-itembc1 {
  background: url("../assets/images/icon_17.png") no-repeat 95% 80%,
  linear-gradient(133deg, #ffffff 0%, #e5f1ff 100%);
}
.top-itembc2 {
  background: url("../assets/images/icon_18.png") no-repeat 95% 80%,
  linear-gradient(133deg, #ffffff 0%, #fff5ec 100%);
}
.top-itembc3 {
  background: url("../assets/images/icon_19.png") no-repeat 95% 80%,
  linear-gradient(133deg, #ffffff 0%, #e5f1ff 100%);
}
.top-itembc4 {
  background: url("../assets/images/icon_20.png") no-repeat 95% 80%,
  linear-gradient(133deg, #ffffff 0%, #fff5ec 100%);
}
.tb-icon {
  width: 18px;
  height: 18px;
  display: inline-block;
  background: url("../assets/images/icon_16.png") no-repeat;
}

</style>
